<template>
	<view class="content">
		
		<view class="box">
			<view class="top">
				<text class="title" >{{ title?title:'活动签到' }}</text>
				<text class="sus" v-if="show" >签到成功!</text>
			</view>
			<view class="down">
				<view class="code" v-if="show" >
					<view class="codes">
						<text class="codes-title" >此次活动您的臂贴号码为</text>
						<text class="codes-title2" >{{ code }}</text>
					</view>
					<text class="code-title" >请联系工作人员领取臂贴!</text>
				</view>
				<view class="btnBox" v-else >
					<button class="btn" @tap="signIn" >签到</button>
				</view>
			</view>
		</view>
		
		<view class="ball">
			<image src="https://friend.tanshishang.cn/assets/img/ball.png" mode="aspectFit"></image>
		</view>

		

	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		computed: {
			...mapState(['token', 'userId'])
		},
		data() {
			return {
				id: '',
				title:'',
				code:'',
				show:false
			};
		},
		onLoad(data) {
			if (data.scene) {
				this.id = data.scene;
			}
		},
		onShow() {
			// console.log('token:' + this.token);
			// if (!this.token) {
			// 	uni.showModal({
			// 		title: '您还未登录',
			// 		content: '点击登录,登录后可查看更多!',
			// 		showCancel: true,
			// 		confirmText: '登录',
			// 		success: (res) => {
			// 			// console.log(res);
			// 			if (res.confirm) {
			// 				uni.navigateTo({
			// 					url: "/pages/index/wxLogin"
			// 				})
			// 			} else if (res.cancel) {
			// 				console.log('用户点击取消');
			// 			}
			
			// 		}
			// 	});
			// }else{
			// 	//获取数据
			// 	this.getData();
			// }
			this.getData();
		},
		methods: {
			//获取数据
			async getData() {
				try {
					let params = {
						token: this.token,
						id: this.id
					}
					let res = await this.$request.request.get('/api/active/detail', params);
					console.log(res);
					this.title = res.data.data.title;
				} catch (err) {
					this.$request.error(err, this)
				}
			},
			//点击签到
			async signIn() {
				try {
					let params = {
						token: this.token,
						userId: this.userId,
						activeId: this.id
					}
					let res = await this.$request.request.get('/api/wechat/sign', params);
					console.log(res.data);
					if(res.code == 200){
						uni.showToast({
							title:res.msg,
							mask:true
						})
						this.show = true;
						this.code = res.data.num;
					}
				} catch (err) {
					this.$request.error(err, this)
				}
			}
		}
	}
</script>

<style lang="scss">
	@import 'signIn.scss'
</style>
